class Solution:
    # 同cpp的暴力版本，python时间限制比较松，能过
    def findValidSplit(self, nums: List[int]) -> int:
        n = len(nums)
        bound = n - 1
        while bound:
            if math.gcd(nums[0], nums[bound]) == 1:
                bound -= 1
            else:
                break

        if bound == n - 1:
            return -1

        i = 1
        while i <= bound:
            for j in range(n - 1, bound, -1):
                if math.gcd(nums[i], nums[j]) != 1:
                    bound = j
                    break
            if bound >= n - 1:
                return -1
            i += 1

        return bound
